package thread;
/**
 守护线程:java进程中至少要有一条用户线程活着，否则进程就会结束，结束时发现还有守护线程
 活着会强行杀死这些线程
 */
public class DaemonThreadDemo {
    public static void main(String[] args) {
        Thread rose=new Thread("rose"){
          public void run(){
              for(int i=0;i<5;i++){
                  System.out.println(getName()+":let me go!");
                  try {
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
              System.out.println(getName()+":啊啊啊AAAaaaa....");
              System.out.println("扑通!");
          }
        };
        Thread jack=new Thread("jack"){
            public void run(){
                while (true){
                    System.out.println(getName()+":You jump!I jump!");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        rose.start();
        jack.setDaemon(true);//将jack线程设置为守护线程;
        jack.start();

        while (true);
    }
}
